package com.example.yls.drawerdemo;

import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private LinearLayout id_ll_left;
    private DrawerLayout drawerLayout;
    private TextView tv_content;
    private NavigationView navigationView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        id_ll_left = findViewById(R.id.id_ll_left);
        drawerLayout = findViewById(R.id.id_dl_root);
        tv_content = findViewById(R.id.tv_content);
        navigationView = findViewById(R.id.id_nv_root);

        navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.icon_a:
                        Toast.makeText(MainActivity.this, "about", Toast.LENGTH_SHORT).show();
                        return true;
                }


                return false;
            }
        });


        findViewById(R.id.close_left).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                drawerLayout.closeDrawer(Gravity.START);

            }
        });

        findViewById(R.id.open_leftMeun).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                drawerLayout.openDrawer(Gravity.START);
            }
        });

        findViewById(R.id.open_rightMeun).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                drawerLayout.openDrawer(Gravity.END);
            }
        });

        drawerLayout.addDrawerListener(new DrawerLayout.DrawerListener() {
            @Override
            public void onDrawerSlide(View drawerView, float slideOffset) {
                drawerView.setRotation(360 * slideOffset);
                tv_content.setRotationX(360 * slideOffset + 1);
                tv_content.setRotationY(360 * slideOffset + 3);
            }

            @Override
            public void onDrawerOpened(View drawerView) {

            }

            @Override
            public void onDrawerClosed(View drawerView) {

            }

            @Override
            public void onDrawerStateChanged(int newState) {

            }
        });
    }

}
